export function validatePhone(rule, value, callback) {
  if (value === "") {
    callback(new Error("请输入手机号"));
  } else {
    if (!/^1[3456789]\d{9}$/.test(value)) {
      callback(new Error("请输入正确的手机号"));
    } else {
      callback();
    }
  }
}

export function getDateRange(){

  let nowDate = new Date()
  let lastDate = new Date(nowDate - 1000 * 60 * 60 * 24 * 30)

  let nowYear = nowDate.getFullYear()
  let lastYear = lastDate.getFullYear()

  let nowMonth = nowDate.getMonth() + 1
  let lastMonth = lastDate.getMonth() + 1

  let nowDay = nowDate.getDate()
  let lastDay = lastDate.getDate()

  if (nowMonth >= 1 && nowMonth <= 9) {
    nowMonth = "0" + nowMonth
  }
  if (lastMonth >= 1 && lastMonth <= 9) {
    lastMonth = "0" + lastMonth
  }

  if (nowDay >= 0 && nowDay <= 9) {
    nowDay = "0" + nowDay
  }
  if (lastDay >= 0 && lastDay <= 9) {
    lastDay = "0" + lastDay
  }
  let currentdate = `${nowYear}-${nowMonth}-${nowDay}`
  let beforeDate = `${lastYear}-${lastMonth}-${lastDay}`
  return [beforeDate, currentdate]
}

export default {
  validatePhone,
  getDateRange
}
